﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;

namespace QuanLyKho.Control
{
    public partial class Lss_Kehoach : UserControl
    {
        public Lss_Kehoach()
        {
            InitializeComponent();
            loaddata();
        }

        public void loaddata()
        {
            DataTable data = new DataTable();
            data.Columns.Add("MaSanPham");
            data.Columns.Add("TenSanPham");
            data.Columns.Add("DV");
            data.Columns.Add("KhoVai");
            data.Columns.Add("KhoGSD");
            for (int i = 0; i < 12; i++)
            {
                data.Rows.Add(i, i, i, i, i);
            }

            gridLss_KeHoach.DataSource = data;
            RepositoryItemComboBox rc = new RepositoryItemComboBox();
            rc.Items.AddRange(new object[] { "0234", "1adsf", "2asdf", "3dfgf" });
            rc.Items.Add("");
            gridLss_KeHoach.ForceInitialize();
            gvLss_KeHoach.Columns[1].ColumnEdit = rc;

        }

        private void gvLss_KeHoach_ShownEditor(object sender, EventArgs e)
        {
            if (gvLss_KeHoach.FocusedColumn.ToString() == "Ten San Pham")
            {
                (gvLss_KeHoach.ActiveEditor as ComboBoxEdit).ShowPopup();
                (gvLss_KeHoach.ActiveEditor as ComboBoxEdit).TextChanged += cbbMaHang_SelectedIndexChanged;
            }
            if (Convert.ToInt32(gvLss_KeHoach.GetFocusedDataSourceRowIndex().ToString()) + 1 == gvLss_KeHoach.RowCount)
            {
                (gridLss_KeHoach.MainView as DevExpress.XtraGrid.Views.Grid.GridView).AddNewRow();
            }
        }

        private void cbbMaHang_SelectedIndexChanged(object sender, EventArgs e)
        {
            (gvLss_KeHoach.ActiveEditor as ComboBoxEdit).ShowPopup();
        }

        private void gvLss_KeHoach_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            //if (gvLss_KeHoach.FocusedColumn == MaSanPham)
            //{
            //    (gvLss_KeHoach.ActiveEditor as ComboBoxEdit).ShowPopup();
            //}
        }
    }
}
